package com.lagou.sort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

//Reduccer对应的参数类型是两对kv
//
public class SortReducer extends Reducer<LongWritable, LongWritable, LongWritable ,LongWritable> {
    private static LongWritable line = new LongWritable(0);
    //接收来自mapper端的数据<k2,[v2,v2,v2...]>,此时，数据已经按key进行排序
    @Override
    protected void reduce(LongWritable key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
        // 循环遍历values
        for (LongWritable v : values) {
            line = new LongWritable(line.get() +1);
            context.write(line, key);


        }
    }
}
